#ifndef __SCUTABLE_H_INCLUDED
#define __SCUTABLE_H_INCLUDED

#include <scos.h>

#ifdef __cplusplus
extern "C" {
#endif

#define tbladd(tbl, data) _tbladd(tbl, (void*)data)
#define tbladdi(tbl, data, i) _tbladdi(tbl, (void*)data, i)
#define tbladdnew(tbl, data) _tbladdnew(tbl, (void**)data)
#define tbladdnewi(tbl, data, i) _tbladdnewi(tbl, (void**)data, i)
#define tblget(tbl, i, data) _tblget(tbl, i, (void**)data)
#define tblgetnextelement(tbl, i, data) _tblgetnextelement(tbl, i, (void**)data)

typedef struct table_hash_s
{
  void *data;
  int i;
  struct table_hash_s *next;
} table_hash_t;

typedef struct table_s
{
  int size, length, elements, hashsize, hashlength;
  void **data;
  scos_mutex_t lock;
  struct table_hash_s **hash;
} table_t;

int tblcreate(table_t *tbl, int size);
int tbldestroy(table_t *tbl, int dofree);
int tblclear(table_t *tbl, int dofree);
int _tbladd(table_t *tbl, void *data);
int _tbladdi(table_t *tbl, void *data, int i);
int _tbladdnew(table_t *tbl, void **data);
int _tbladdnewi(table_t *tbl, void **data, int i);
int tbldel(table_t *tbl, int i, int dofree);
void *_tblget(table_t *tbl, int i, void** data);
int tblgetnexti(table_t *tbl, int i);
void *_tblgetnextelement(table_t *tbl, int *i, void **data);
int tblgetelements(table_t *tbl);
int tblcreatehash(table_t *tbl, int size, int length);
int _tbldohash(table_t *tbl, void *data);
int tbladdhash(table_t *tbl, void *data, int i);
int tblfindhash(table_t *tbl, void *data);
int tbldelhash(table_t *tbl, void *data);
int tbldestroyhash(table_t *tbl);
int tblsort(table_t *tbl, int(*compar)(const void*, const void*));
int tblcopy(table_t *dst, table_t *src, int dofree);

#define tblsortslice(x, y) 0

#ifdef __cplusplus
}
#endif

#endif /* __SCUTABLE_H_INCLUDED */
